package com.st.mall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.st.mall.ware.entity.PurchaseEntity;
import com.st.mall.ware.service.PurchaseService;
import com.st.common.utils.PageUtils;
import com.st.common.utils.R;
import vo.MergeVo;
import vo.PurchaseDoneVo;


/**
 * 采购信息
 *
 * @author fg
 * @email f@163.com
 * @date 2023-02-26 20:47:57
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 查询未领取的采购单
     */
    @GetMapping("/unreceive/list")
    public R unReceiveList(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryUnReceive(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }
    /**
     * 完成采购
     */
    @PostMapping("/done")

    public R doneP(@RequestBody PurchaseDoneVo purchase){
        purchaseService.doneP(purchase);
        return R.ok();
    }

    /**
     * 领取采购单
     */
    @GetMapping("/received")
    public R received(@RequestBody List<Long> pId){
         purchaseService.received(pId);
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }
    /**
     * 合并采购需求
     */
    @PostMapping("/merge")
    public R merge(@RequestBody MergeVo mergeVo){
        purchaseService.mergeByPurchaseId(mergeVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
